// Copyright 2008 Senary
// See credits.txt for details.

// This file is part of Omega VII.

// Omega VII is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Omega VII is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Omega VII.  If not, see <http://www.gnu.org/licenses/>.

#include "../CppUnitLite/TestHarness.h"

#include "../Constants.h"
#include "../Vector.h"

// The test suite needs to generate strings from vectors
SimpleString StringFrom(Vector const& value)
{
	return SimpleString(value.toString().c_str());
}


TEST(AdditionAndScalarMultiplication, Vector) {
	Vector a(1.0, 2.0, 3.0);
	Vector b(6.0, 7.0, 7.0);

	CHECK_EQUAL(Vector(8.0, 11.0, 13.0), a * 2 + b);
}

TEST(DotProduct, Vector) {
	Vector a(1.0, 2.0, 3.0);
	Vector b(6.0, 7.0, 7.0);

	DOUBLES_EQUAL(41.0, dot(a, b), 0.00001);
}

TEST(Rotation, Vector) {
	Vector e1(1.0, 0.0, 0.0);
	Vector e2(0.0, 1.0, 0.0);
	Vector e3(0.0, 0.0, 1.0);
	Vector a(e1);

	a.rotate(e3, M_PI / 4.0);

	DOUBLES_EQUAL(0.0, (a - Vector(0.5 * sqrt(2.0), 0.5 * sqrt(2.0), 0.0)).r2(), 0.0001);

	Vector b(a);
	Vector c(a);

	b.rotateTowards(e2, 1.0); // 1.0 is bigger than the angle in between
	CHECK_EQUAL(e2, b);

	c.rotateTowards(e2, 0.1);
	DOUBLES_EQUAL(0.0, (c - Vector(cos(M_PI / 4.0 + 0.1), sin(M_PI / 4.0 + 0.1), 0.0)).r2(), 0.0001);
}